package org.theSeed.base.exp;

import cn.hutool.json.JSONUtil;
import org.theSeed.base.pojo.sysEnum.SysCode;

import java.util.Arrays;
import java.util.List;

/**
 * 业务异常
 * 提示信息能直接使用
 */
public class BuzExp extends RuntimeException{
    //错误码
    private Integer code;

    //错误消息
    private List<String> message;

    public BuzExp() {
    }

    /**
     * 系统枚举错误消息
     * @param sysCode
     */
    public BuzExp(SysCode sysCode) {
        super(sysCode.getDescribStr());
        this.code = sysCode.getCode();
        this.message = Arrays.asList(sysCode.getDescribStr());
    }

    /**
     * 自定义错误消息
     * @param sysCode
     * @param message
     */
    public BuzExp(SysCode sysCode,String message) {
        super(message);
        this.code = sysCode.getCode();
        this.message = Arrays.asList(sysCode.getDescribStr());
    }

    /**
     * 完全自定义
     * @param code
     * @param message
     */
    public BuzExp(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = Arrays.asList(message);
    }

    /**
     * 完全自定义
     * @param code
     * @param messageList
     */
    public BuzExp(Integer code, List<String> messageList) {
        super(JSONUtil.toJsonStr(messageList));
        this.code = code;
        this.message = messageList;
    }
}
